package com.gl.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gl.entity.EduSubject;
import com.gl.entity.subject.SubjectAdd;
import com.gl.entity.subject.SubjectOne;
import com.gl.service.EduSubjectService;
import com.gl.utils.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-12-14
 */
@RestController
@RequestMapping("/subject")
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    //获取所有分类数据，返回一级分类集合，一级分类里面有各自下所有二级分类集合
    @GetMapping("getList")
    public List<SubjectOne> getList(){
        List<SubjectOne> list = subjectService.getList();
        return list;
    }






    //后台
    //获取所有分类数据，返回一级分类集合，一级分类里面有各自下所有二级分类集合
    @GetMapping("getBackList")
    public CommonResponse getBackList(){
        List<SubjectOne> list = subjectService.getList();
        return CommonResponse.ok().data("list",list);
    }

    //查询所有一级分类
    @GetMapping("getOneSubject")
    public CommonResponse getOneSubject(){
        QueryWrapper<EduSubject> wrapper = new QueryWrapper<>();
        //父id是0的分类就是一级分类
        wrapper.eq("parent_id",0);
        //只需要查询出id和title
        wrapper.select("id","title");
        List<EduSubject> list = subjectService.list(wrapper);

        return CommonResponse.ok().data("list",list);
    }

    //添加课程分类
    @PostMapping("addSubject")
    public CommonResponse addSubject(@RequestBody SubjectAdd subjectAdd){
        subjectService.addSubject(subjectAdd);
        return CommonResponse.ok();
    }


}

